package com.spa.interfaces.common;

import com.spa.application.query.GaodeDistanceQuery;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.infrastructure.service.gaode.GaodeService;
import com.spa.infrastructure.service.gaode.result.ReGeoResult;
import com.spa.interfaces.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("gaode")
public class GaoDeController extends BaseController {

    @Autowired
    private GaodeService gaodeService;

    @PostMapping("distance")
    public ResponseMessage<Integer> distance(@RequestBody GaodeDistanceQuery query) throws IOException {
        return responseHelper.success(gaodeService.getDistance(query.getOrigins(), query.getDestination()));
    }

    @PostMapping("regeo")
    public ResponseMessage<ReGeoResult.AddressComponent> regeo(@RequestBody GaodeDistanceQuery query) throws IOException {
        return responseHelper.success(gaodeService.regeo(query.getOrigins()));
    }

    @PostMapping("getFormattedAddress")
    public ResponseMessage<String> getFormattedAddress(@RequestBody GaodeDistanceQuery query) throws IOException {
        return responseHelper.success(gaodeService.getFormattedAddress(query.getOrigins()));
    }

}
